import ConfirmComponent from './index.vue';

let $vm;

export default {
    install (vue) {
        if (!$vm) {
            const Confirm = vue.extend(ConfirmComponent)
            $vm = new Confirm({
                el: document.createElement('div')
            });
            document.body.appendChild($vm.$el);
        }
        
        const confirm = {
            show (options) {
                if (typeof options === 'object') {
                    $vm.msg = options.msg? options.msg : "";
                    $vm.title = options.title? options.title : "提示";
                    $vm.okBtn = options.okBtn? options.okBtn : "确定";
                    $vm.cancelBtn = options.okBtn? options.cancelBtn : "取消";
                    $vm.okCb = options.okCb? options.okCb: null;
                    $vm.cancelCb = options.cancelCb? options.cancelCb: null;
                } else if (typeof options === 'string') {
                    $vm.$el.querySelector('.aui-confirm__inner__dialog__content__msg').innerHTML = options
                }
                $vm.onShow($vm);
            },
            hide () {
                $vm.show = !1;
            }
        }

        if (!vue.$aui) {
            vue.$aui = {
                confirm
            }
        } else {
            vue.$aui.confirm = confirm
        }

        vue.mixin({
            created: function () {
                this.$aui = vue.$aui
            }
        });
    }
}
